So it can be shared with soft reboots.
Signed-off-by: Colin Walters <walters@verbum.org>
#endif
+/**
+ * otcore_mount_boot:
+ *
+ * Mount /boot as a bind mount for a deployment if it's on the same partition
+ * as the physical root.
+ */
+gboolean
+otcore_mount_boot (const char *physical_root, const char *deployment, GError **error)
+{
+ g_autofree char *boot_loader = g_build_filename (physical_root, "boot/loader", NULL);
+ struct stat stbuf;
+
+ /* If /boot is on the same partition, use a bind mount to make it visible
+ * at /boot inside the deployment.
+ */
+ if (!(lstat (boot_loader, &stbuf) == 0 && S_ISLNK (stbuf.st_mode)))
+ return TRUE;
+
+ g_autofree char *target_boot = g_build_filename (deployment, "boot", NULL);
+ if (!(lstat (target_boot, &stbuf) == 0 && S_ISDIR (stbuf.st_mode)))
+ return TRUE;
+
+ g_autofree char *src_boot = g_build_filename (physical_root, "boot", NULL);
+ if (mount (src_boot, target_boot, NULL, MS_BIND | MS_SILENT, NULL) < 0)
+ return glnx_throw (error, "failed to bind mount /boot");
+
+ return TRUE;
+}
+
/**
* otcore_mount_etc:
*
gboolean otcore_mount_rootfs (RootConfig *rootfs_config, GVariantBuilder *metadata_builder,
const char *root_mountpoint, const char *deploy_path,
const char *mount_target, bool *out_using_composefs, GError **error);
+gboolean otcore_mount_boot (const char *physical_root, const char *deploy_path, GError **error);
gboolean otcore_mount_etc (GKeyFile *config, GVariantBuilder *metadata_builder,
const char *mount_target, GError **error);
g_variant_builder_add (&metadata_builder, "{sv}", OTCORE_RUN_BOOTED_KEY_SYSROOT_RO,
g_variant_new_boolean (sysroot_readonly));
- /* Prepare /boot.
- * If /boot is on the same partition, use a bind mount to make it visible
- * at /boot inside the deployment. */
- if (snprintf (srcpath, sizeof (srcpath), "%s/boot/loader", root_mountpoint) < 0)
- err (EXIT_FAILURE, "failed to assemble /boot/loader path");
- if (lstat (srcpath, &stbuf) == 0 && S_ISLNK (stbuf.st_mode))
- {
- if (lstat ("boot", &stbuf) == 0 && S_ISDIR (stbuf.st_mode))
- {
- if (snprintf (srcpath, sizeof (srcpath), "%s/boot", root_mountpoint) < 0)
- err (EXIT_FAILURE, "failed to assemble /boot path");
- if (mount (srcpath, TMP_SYSROOT "/boot", NULL, MS_BIND | MS_SILENT, NULL) < 0)
- err (EXIT_FAILURE, "failed to bind mount %s to boot", srcpath);
- }
- }
+ if (!otcore_mount_boot (root_mountpoint, TMP_SYSROOT, &error))
+ errx (EXIT_FAILURE, "%s", error->message);
/* Prepare /etc.
* No action required if sysroot is writable. Otherwise, a bind-mount for